from pyhessian.client import HessianProxy
from suds.client import Client


class ClientUtils:

    def __init__(self, config):
        self.config = config

    def get_client(self):
        if not hasattr(self, 'client'):
            type = self.config.get_value('type')
            if type == 'hessian':
                print('init Hessian client~~~~~~~~')
                self.client = HessianProxy(self.config.get_value('url'))
            elif type == 'soap':
                print('init soap client~~~~~~~~')
                self.client = Client(self.config.get_value('url')).service
            return self.client
        else:
            return self.client

    def call(self, args):
        return getattr(self.get_client(), self.config.get_value('method'))(args)
